package cn.com.idmy.mq.model.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

@Getter
@AllArgsConstructor
public enum MqDelayLevel {
    ZERO(0, 0L, "0s"),
    ONE(1, 1000L, "1s"),
    TWO(2, 5000L, "5s"),
    THREE(3, 10000L, "10s"),
    FOUR(4, 30000L, "30s"),
    FIVE(5, 60000L, "1m"),
    SIX(6, 120000L, "2m"),
    SEVEN(7, 180000L, "3m"),
    EIGHT(8, 240000L, "4m"),
    NINE(9, 300000L, "5m"),
    TEN(10, 360000L, "6m"),
    ELEVEN(11, 420000L, "7m"),
    TWELVE(12, 480000L, "8m"),
    THIRTEEN(13, 540000L, "9m"),
    FOURTEEN(14, 600000L, "10m"),
    FIFTEEN(15, 1200000L, "20m"),
    SIXTEEN(16, 1800000L, "30m"),
    SEVENTEEN(17, 3600000L, "1h"),
    EIGHTEEN(18, 7200000L, "2h");
    final int level;
    final long delay;
    final String name;

    public static MqDelayLevel getByLevel(int level) {
        return Arrays.stream(MqDelayLevel.values()).filter(item -> Objects.equals(item.getLevel(), level)).findFirst().orElse(ZERO);
    }
}
